package com.blkj.iam.system.converter;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blkj.iam.system.model.entity.Dept;
import com.blkj.iam.system.model.form.DeptForm;
import com.blkj.iam.system.model.vo.DeptPageVO;
import com.blkj.iam.system.model.vo.DeptVO;
import org.mapstruct.Mapper;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 部门对象转换器
 *
 * @author haoxr
 * @since 2022/7/29
 */
@Mapper(componentModel = "spring")
public interface DeptConverter {

    DeptForm toForm(Dept entity);
    
    DeptVO toVo(Dept entity);

    Dept toEntity(DeptForm deptForm);

    // 自定义映射方法：将 List<String> 转换为 String
    default String map(List<String> value) {
        if (value == null || value.isEmpty()) {
            return null;
        }
        return String.join(",", value);
    }

    // 自定义映射方法：将 String 转换为 List<String>
    default List<String> map(String value) {
        if (value == null || value.isEmpty()) {
            return Collections.emptyList();
        }
        return Arrays.asList(value.split(","));
    }

    Page<DeptPageVO> toPageVo(Page<Dept> deptPage);
}